﻿using LD.Host;
using LD.Tool;
using PubSub;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LD.Tool
{
    [Tool(Text = "FPC测试数据解析", FrmParam = "ToolFpcFrm", ToolType = ToolEnum.项目, Show = false)]
    public class ToolFpc : BaseTool
    {
        public override OpResult Execute(TB_Tool model)
        {
            try
            {
                stopwatch.Start();
                double up = 0;
                double down = 0;
                double testVal = 0;
                if (model.Param != null)
                {
                    string[] testData = Cache.Var.Where(p => p.Name == model.Param).FirstOrDefault().Val.ToString().Split(',');
                    if (testData.Length >= 2)
                    {
                        if (double.TryParse(testData[1], out testVal))
                        {
                            up = (double)Cache.GetCache(CONST.SHARP_FPCUP);
                            down = (double)Cache.GetCache(CONST.SHARP_FPCDOWN);
                            if (up >= testVal && down <= testVal)
                            {
                                isSuccess = true;
                            }
                        }
                    }
                }
                if (!isSuccess)
                    Log(model, $"测试失败:上限【{up}】下限【{down}】测试值【{testVal}】", LogLevel.警告);
            }
            catch (Exception ex)
            {
                Log(model, ex.Message, LogLevel.严重);
            }
            finally
            {
                stopwatch.Stop();
            }
            return new OpResult() { IsSuccess = isSuccess, Message = message, ExecuteTime = stopwatch.ElapsedMilliseconds };
        }
    }
}
